<?php

class FeedbackModule extends fvModule {
	
	function __construct() {
		$moduleName = strtolower ( substr ( __CLASS__, 0, - 6 ) );
		
		parent::__construct ( fvSite::$fvConfig->get ( "modules.{$moduleName}.smarty.template" ), fvSite::$fvConfig->get ( "modules.{$moduleName}.smarty.compile" ), fvSite::$Layoult );
	}
	
	function showIndex() {
		return '';
	}
	
	function showFull() {
		return '';
	}
	
	function showChangecountry() {
		$request = fvRequest::getInstance ();
		$ResortsNames [0] = "Выберите курорт";
		$ResortsIDs [0] = 0;
		if ($request->getRequestParameter ( 'country_id' )) {
			$Turtess = new fvTurtessXML ( );
			$TurtessResorts = $Turtess->getResorts ();
			foreach ( $TurtessResorts as $Resort ) {
				if ($Resort['resortCountryKey'] == $request->getRequestParameter ( 'country_id' ))
				{
					$ResortsNames [] = $Resort ['resortName'];
					$ResortsIDs [] = $Resort ['resortKey'];
				}
			}
		} 
		$this->__assign(array("RESORTS_NAMES" => $ResortsNames, "RESORTS_IDS" => $ResortsIDs));
		return $this->__display("feedback_changecountry.tpl");
//		return $return_text;
	}
	
	function showChangeresort() {
		$request = fvRequest::getInstance ();
		$HotelsNames [0] = "Выберите отель";
		$HotelsIDs [0] = 0;
		if ($request->getRequestParameter ( 'resort_id' )!=0 ) {
			$Turtess = new fvTurtessXML ( );
			$TurtessHotels = $Turtess->getHotels ();
			foreach ( $TurtessHotels as $Hotel ) {
				if ($Hotel['hotelresortKey'] == $request->getRequestParameter ( 'resort_id' ))
				{
					$HotelsNames [] = $Hotel ['hotelName'];
					$HotelsIDs [] = $Hotel ['hotelKey'];
				}
			}
		}
		$this->__assign(array("HOTELS_NAMES" => $HotelsNames, "HOTELS_IDS" => $HotelsIDs));
		return $this->__display("feedback_changeresort.tpl");
	}
	
	function showAddtext() {
		//		var_dump($_REQUEST);
		$Turtess = new fvTurtessXML ( );
		$TurtessCountries = $Turtess->getCountries ();
		$CountriesNames [0] = "Выберите страну";
		$CountriesIDs [0] = 0;
		foreach ( $TurtessCountries as $Country ) {
			$CountriesNames [] = $Country ['countryName'] . ' (' . $Country ['countryNameLat'] . ')';
			$CountriesIDs [] = $Country ['countryKey'];
		}
		$TurtessResorts = $Turtess->getResorts ();
		$ResortsNames [0] = "Выберите курорт";
		$ResortsIDs [0] = 0;
		foreach ( $TurtessResorts as $Resort ) {
			$ResortsNames [] = $Resort ['resortName'];
			$ResortsIDs [] = $Resort ['resortKey'];
		}
		$TurtessHotels = $Turtess->getHotels ();
		$HotelsNames [0] = "Выберите отель";
		$HotelsIDs [0] = 0;
		foreach ( $TurtessHotels as $Hotel ) {
			$HotelsNames [] = $Hotel ['hotelName'];
			$HotelsIDs [] = $Hotel ['hotelKey'];
		}
		$this->__assign ( array ("COUNTRIES_NAMES" => $CountriesNames, "COUNTRIES_IDS" => $CountriesIDs, "RESORTS_NAMES" => $ResortsNames, "RESORTS_IDS" => $ResortsIDs, "HOTELS_NAMES" => $HotelsNames, "HOTELS_IDS" => $HotelsIDs, "ERRORS" => fvSite::$fvSession->get ( "ERROR" ), "m" => fvSite::$fvSession->get ( "m" ), "FeedbackTypesManager" => FeedbackTypesManager::getInstance (), "LoggedUser" => fvSite::$fvSession->get ( "login/loggedUser" ) ) );
		fvSite::$fvSession->set ( "ERROR", NULL );
		fvSite::$fvSession->set ( "m", NULL );
		return $this->__display ( "feedback_addtext.tpl" );
	}
	
	function showAddvideo() {
		$LoggedUser = fvSite::$fvSession->get ( "login/loggedUser" );
		$feedback_id = fvSite::$fvSession->get ( "feedback_id" );
		if (! $LoggedUser)
			fvDispatcher::getInstance ()->redirect ( "/" );
		if (! $feedback_id)
			fvDispatcher::getInstance ()->redirect ( "/feedback/addtext/" );
			//		var_dump(exec("ls -l /usr/bin/lame", $arr));
		//		passthru("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tv/ffmpeg/lame/lib;nohup ffmpeg -i /home/tv/web/uploads/NBKSIPukr.avi -ar 22050 -f flv -s 320x240 /home/tv/web/uploads/123456789.flv >& /dev/null &");
		//		`export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tv/ffmpeg/lame/lib;nohup ffmpeg -i /home/tv/web/uploads/NBKSIPukr.avi -ar 22050 -f flv -s 320x240 /home/tv/web/uploads/123456.flv >& /dev/null &`;
		//		shell_exec('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tv/ffmpeg/lame/lib;nohup ffmpeg -i /home/tv/web/uploads/NBKSIPukr.avi -ar 22050 -f flv -s 320x240 /home/tv/web/uploads/12345.flv &');
		//		var_dump(exec('ffmpeg -i /home/tv/web/uploads/1.wmv -ar 22050 -ab 32 -f flv -s 320x240 /home/tv/web/uploads/video.flv', $arr));
		//		echo "<pre>";var_dump($arr);echo "</pre>";
		//		die();
		//		$ffmpegInstance = new ffmpeg_movie ( '/home/tv/web/uploads/NBKSIPukr.avi' );
		//		$fwidth = $ffmpegInstance->getFrameWidth ();
		//		$fheight = $ffmpegInstance->getFrameHeight ();
		//		$fduration = $ffmpegInstance->getDuration ();
		//		if (exec("nohup /usr/X11R6/bin/ffmpeg -i /home/tv/web/uploads/1.wmv -an -ss 00:00:30 -r 1 -vframes 1 -s 320×240 -y -f mjpeg /home/tv/web/uploads/images/screenshot.jpg &"))
		//			echo "1234";
		//		else 
		//			echo "Не работает?";
		//		$result_thumb = exec ( "ffmpeg -i /home/tv/web/uploads/1.flv -an -ss 00:00:00 -r 1 -vframes 1 -s 120?100 -y -f mjpeg /home/tv/web/uploads/1-thumb.jpg" );
		//		echo $fwidth . " -> " . $fheight . " -> " . $fduration . "<br><br>";
		//		$fduration_part = $fduration / 17;
		//		$fduration_const = $fduration / 17;
		//		for($i = 1; $i < 17; $i ++) {
		//			$res[$i] = $this->secs_to_string_compact ( $fduration_part );
		//			if ($i <= 9) {
		//				$a = "00" . $i;
		//			} else if ($i > 9) {
		//				$a = "0" . $i;
		//			}
		//			$res = exec ( "ffmpeg -i /home/tv/web/uploads/1.flv -an -ss " . $res [$i] . " -r 1 -vframes 1 -s 120?100 -y -f mjpeg /home/tv/web/uploads/images/a-" . $a . ".jpg" );
		//			$fduration_part = $fduration_part + $fduration_const;
		//			echo $res [$i] . " -> " . $fduration_part . "<br>";
		//		}
		$Video = VideoManager::getInstance ()->getAll ( "(is_show=0 or is_show=1) and feedback_id=" . $feedback_id . " and user_id=" . $LoggedUser->getPk () );
		$this->__assign ( 'Videos', $Video );
		return $this->__display ( "feedback_addvideo.tpl" );
	}
	
	function showModerate() {
		$request = fvRequest::getInstance ();
		$Turtess = new fvTurtessXML ( );
		$TurtessCountries = $Turtess->getCountries ();
		$TurtessResorts = $Turtess->getResorts ();
		$TurtessHotels = $Turtess->getHotels ();
		$CountryNames [0] = 'Страна не указана';
		foreach ( $TurtessCountries as $Country ) {
			$CountryNames [$Country ['countryKey']] = $Country ['countryName'];
		}
		$ResortNames [0] = 'Курорт не указан';
		foreach ( $TurtessResorts as $Resort ) {
			$ResortNames [$Resort ['resortKey']] = $Resort ['resortName'];
		}
		$HotelNames [0] = 'Отель не указан';
		foreach ( $TurtessHotels as $Hotel ) {
			$HotelNames [$Hotel ['hotelKey']] = $Hotel ['hotelName'];
		}
		if ($request->getRequestParameter ( 'id' )) {
			$Feedbacks = FeedbackManager::getInstance ()->getByPk ( $request->getRequestParameter ( 'id' ) );
			$path = str_pad ( $Feedbacks->user_id, 8, '0', STR_PAD_LEFT );
			$this->__assign ( 'path', $path );
			$this->__assign ( 'Videos', VideoManager::getInstance ()->getAll ( 'feedback_id=' . $request->getRequestParameter ( 'id' ) ) );
			$this->__assign ( 'Images', ImageManager::getInstance ()->getAll ( 'feedback_id=' . $request->getRequestParameter ( 'id' ) ) );
			$template = "feedback_moderate_text.tpl";
		} else {
			$Feedbacks = FeedbackManager::getInstance ()->getAll ( "is_show=0" );
			$template = "feedback_moderate.tpl";
		}
		$this->__assign ( 'Feedbacks', $Feedbacks );
		$this->__assign ( 'TurtessCountry', $CountryNames );
		$this->__assign ( 'TurtessResort', $ResortNames );
		$this->__assign ( 'TurtessHotel', $HotelNames );
		return $this->__display ( $template );
	}
	
	function showAddimage() {
		$LoggedUser = fvSite::$fvSession->get ( "login/loggedUser" );
		$feedback_id = fvSite::$fvSession->get ( "feedback_id" );
		if (! $LoggedUser)
			fvDispatcher::getInstance ()->redirect ( "/" );
		if (! $feedback_id)
			fvDispatcher::getInstance ()->redirect ( "/feedback/addtext/" );
		$Image = ImageManager::getInstance ()->getAll ( "(is_show=0 or is_show=1) and feedback_id=" . $feedback_id . " and user_id=" . $LoggedUser->getPk () );
		$this->__assign ( 'Images', $Image );
		return $this->__display ( "feedback_addimage.tpl" );
	}
	
	function showSuccess() {
		return "Ваш отзыв успешно сохранён";
	}
}

?>
